package com.education.api.controller.admin.education;

import com.education.business.service.education.TestPaperInfoStudentService;
import com.education.business.service.system.ExamRoomStudentService;
import com.education.common.utils.Result;
import com.education.model.dto.ExamRoomStudentDto;
import com.education.model.dto.StudentInfoDto;
import com.education.model.dto.TestPaperInfoStudentDto;
import com.education.model.entity.ExamRoomStudent;
import com.education.model.entity.TestPaperInfoStudent;
import com.education.model.request.ExamRoomStudentRequest;
import com.education.model.request.PageParam;
import com.education.model.request.TestPaperInfoStudentRequest;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/testStudent")
public class TestPaperInfoStudentController {
    @Autowired
    private TestPaperInfoStudentService testPaperInfoStudentService;
    /**
     * 试卷考生列表
     * @param pageParam
     * @param
     * @return
     */

//    @RequiresPermissions("system:grade:list")
    @RequestMapping(value = "/getTestStudentList",method = RequestMethod.GET)
    public Result list(PageParam pageParam, TestPaperInfoStudentDto testPaperInfoStudent) {
        return Result.success(testPaperInfoStudentService.selectPageList(pageParam, testPaperInfoStudent));
    }
    //批量增加列表
    @RequestMapping(value = "/getPaperStudentList",method = RequestMethod.GET)
    public Result PaperList( PageParam pageParam, TestPaperInfoStudentDto testPaperInfoStudent  ) {
//        testPaperInfoStudent.setExamTaskId(examTaskId);
        return Result.success(testPaperInfoStudentService.paperStudentList(pageParam, testPaperInfoStudent));
    }
    /**
     *
     * @param  @ApiOperation("根据id批量删除用户")
     * @param
     * @return
     */
//    @ResponseBody
    @GetMapping(value = "/delectTestStudentAllById")
    public int deleteStudentAllById(@ApiParam(name = "id",value = "考生id",required = true) @RequestParam(required = true) String id){
        System.out.println(id);
        List idList = new ArrayList();
        String[] strs = id.split(",");
        for (String s: strs
             ) {
            System.out.println(s);
        }
        for (String str:strs){
            idList.add(str);
        }
        return testPaperInfoStudentService.deleteStudentAllById(idList);
    }
    /**
     * 批量增加
     * @param
     * @return
     */

    @PostMapping(value = "/addSelectTestStudent")
    public Result addSelectStudent(@RequestBody TestPaperInfoStudentRequest paperStudent) {
        System.out.println("paperStudent.getRoomId()"+paperStudent.getStudents());
        System.out.println(paperStudent.getStudents().get(0).getId());

        List<TestPaperInfoStudent> studentList = new ArrayList<>();

        for (ExamRoomStudentDto s: paperStudent.getStudents()) {
            TestPaperInfoStudent examRoomStudent = new TestPaperInfoStudent();
            examRoomStudent.setStudentId(s.getStudentInfoId());
            examRoomStudent.setTestPaperInfoId(paperStudent.getTestPaperInfoId());
            studentList.add(examRoomStudent);
        }
        return Result.success( 1,"添加成功",testPaperInfoStudentService.saveOrUpdateBatch(studentList));
    }
    /**
     * 单个删除
     */
    @GetMapping(value = "/deletePapermStudentById")
    public Result deletePaperStudentById(@RequestParam("id") Integer id){
        return Result.success(testPaperInfoStudentService.deleteById(id));
    }

}
